//
//  HXDStatusToolBar.swift
//  weibo
//
//  Created by huxuedong on 15/12/9.
//  Copyright © 2015年 huxuedong. All rights reserved.
//

import UIKit

class HXDStatusToolView: UIView {

    var retweetButton: UIButton?
    var commentButton: UIButton?
    var goodButton: UIButton?
    var statusViewModel: HXDStatusViewModel? {
        didSet {
            retweetButton?.setTitle(statusViewModel?.retweetText, forState: .Normal)
            commentButton?.setTitle(statusViewModel?.commentText, forState: .Normal)
            goodButton?.setTitle(statusViewModel?.goodText, forState: .Normal)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        //创建按钮
        retweetButton = createButton("转发", imageName: "timeline_icon_retweet")
        commentButton = createButton("评论", imageName: "timeline_icon_comment")
        goodButton = createButton("赞", imageName: "timeline_icon_unlike")
        //创建分割线
        let lineOne = createLine()
        let lineTwo = createLine()
        //添加约束
        retweetButton?.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        }
        commentButton?.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(goodButton!)
        }
        goodButton?.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(commentButton!.snp_trailing)
        }
        lineOne.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
        lineTwo.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
    }
    
    private func createButton(title: String, imageName: String) -> UIButton {
        let button = UIButton()
        button.setTitle(title, forState: .Normal)
        button.setTitleColor(UIColor.grayColor(), forState: .Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: .Highlighted)
        button.titleLabel?.font = UIFont.systemFontOfSize(13)
        button.setImage(UIImage(named: imageName), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        addSubview(button)
        return button
    }
    
    private func createLine() -> UIView {
        let imageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(imageView)
        return imageView
    }

}
